<!DOCTYPE html>

<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Live input record and playback</title>
  <style type='text/css'>
    ul {
      list-style: none;
    }

    #recordingslist audio {
      display: block;
      margin-bottom: 10px;
    }
  </style>
  <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>

  <h1>Record to MP3 Test</h1>

  <button onclick="startRecording(this);">record</button>
  <button onclick="stopRecording(this);" disabled>stop</button>

  <button onclick="bb()">kaishi </button>
  <button onclick="pause()">停止</button>



  <h2>Recordings</h2>
  <ul id="recordingslist"></ul>

  <h2>Log</h2>
  <pre id="log"></pre>

  <script>
   
    function __log(e, data) {
      log.innerHTML += "\n" + e + " " + (data || '');
    }

    var audio_context;
    var recorder;

    function startUserMedia(stream) {
      var input = audio_context.createMediaStreamSource(stream);
      __log('Media stream created.');
      __log("input sample rate " + input.context.sampleRate);

      // Feedback!
      //input.connect(audio_context.destination);
      __log('Input connected to audio context destination.');

      recorder = new Recorder(input, {
        numChannels: 1
      });
      __log('Recorder initialised.');
    }

    function startRecording() {
      recorder && recorder.record();
    
      //button.disabled = true;
      //button.nextElementSibling.disabled = false;
      __log('Recording...');

    }

    function stopRecording() {
     
      recorder && recorder.stop();
      //button.disabled = true;
      //button.previousElementSibling.disabled = false;
      __log('Stopped recording.');

      // create WAV download link using audio data blob
      createDownloadLink();

      recorder.clear();
    }
    function aa (){
      
        stopRecording();
        startRecording();
      
      
    }
    var states;
    function bb(){
      startRecording();
      states = setInterval(aa,60000);
    }

    function pause(){
      clearInterval(states);
      stopRecording();
    }

    function createDownloadLink() {
      recorder && recorder.exportWAV(function (blob) {
      });
    }
 
 
    window.onload = function init() {
      try {
        // webkit shim
        window.AudioContext = window.AudioContext || window.webkitAudioContext;
        navigator.getUserMedia = (navigator.getUserMedia ||
          navigator.webkitGetUserMedia ||
          navigator.mozGetUserMedia ||
          navigator.msGetUserMedia);
        window.URL = window.URL || window.webkitURL;

        audio_context = new AudioContext;
        __log('Audio context set up.');
        __log('navigator.getUserMedia ' + (navigator.getUserMedia ? 'available.' : 'not present!'));
      } catch (e) {
        alert('No web audio support in this browser!');
      }

      navigator.getUserMedia({ audio: true }, startUserMedia, function (e) {
        __log('No live audio input: ' + e);
      });
    };
  </script>

  <script src="js/jquery-1.11.0.min.js"></script>
  <script src="recordmp3.js"></script>

</body>

</html>